package com.example.graduate.pojo;

import com.example.graduate.dto.AcceptOrderRequest;
import com.example.graduate.dto.AddOrderRequest;
import com.example.graduate.dto.CancelOrderRequest;
import com.example.graduate.dto.CompleteOrderRequest;
import com.example.graduate.env.OperationTypeEnum;
import com.example.graduate.env.OrderStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RepaySerial {
    /**
     * Id 主键
     */
    private Long Id;

    /**
     * 操作者Id
     */
    private Long userId;

    /**
     * 订单Id
     */
    private Long orderId;

    /**
     *  金额
     */
    private BigDecimal mount;

    /**
     * 订单状态
     */
    private String status;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 结束时间
     */
    private Date finishTime;

    /**
     * 操作类型
     */
    private String operationType;

    /**
     * 发布订单构造器
     * @param addOrderRequest
     * @param orderId
     */
    public RepaySerial(AddOrderRequest addOrderRequest,Long orderId){
        this.status = OrderStatusEnum.RUNNABLE.getCode();
        this.operationType = OperationTypeEnum.PUBLISH.getCode();
        this.userId = addOrderRequest.getUserId();
        this.orderId = orderId;
    }

    /**
     *  取消订单构造器
     * @param cancelOrderRequest
     */
    public RepaySerial(CancelOrderRequest cancelOrderRequest){
        this.status = OrderStatusEnum.RUNNING.getCode();
        this.operationType = OperationTypeEnum.CANCEL.getCode();
        this.userId = Long.parseLong(cancelOrderRequest.getUserId());
        this.orderId = Long.parseLong(cancelOrderRequest.getOrderId());
    }

    /**
     *  取消订单构造器
     * @param completeOrderRequest
     */
    public RepaySerial(CompleteOrderRequest completeOrderRequest){
        this.status = OrderStatusEnum.RUNNING.getCode();
        this.operationType = OperationTypeEnum.over.getCode();
        this.userId = Long.parseLong(completeOrderRequest.getUserId());
        this.orderId = Long.parseLong(completeOrderRequest.getOrderId());
    }

    /**
     *  接收订单构造器
     * @param acceptOrderRequest
     */
    public RepaySerial(AcceptOrderRequest acceptOrderRequest){
        this.status = OrderStatusEnum.RUNNING.getCode();
        this.operationType = OperationTypeEnum.ACCEPT.getCode();
        this.userId = Long.parseLong(acceptOrderRequest.getUserId());
        this.orderId = Long.parseLong(acceptOrderRequest.getOrderId());
    }
}
